package com.dwxt.sport.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.service.AnalysisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = {"场景大数据平台接口"})
public class ShuWeiController {

    @Autowired
    private AnalysisService analysisService;

    @PostMapping("/selectAllScene")
    @ApiOperation(value = "查询所有场景", notes = "查询所有场景", response = BaseResult.class)
    public BaseResult selectAllScene(Integer year, Integer month) {
        List<Map> sceneList = analysisService.selectAllScene(year, month);
        return BaseResult.ok(sceneList);
    }


    @PostMapping("/selectGraph")
    @ApiOperation(value = "根据类型查询图表", notes = "根据类型查询图表", response = BaseResult.class)
    public BaseResult selectGraph(Integer year, Integer month, String[] name, String category,Integer type) {
        return analysisService.selectGraph(year, month, name, category,type);
    }

    @PostMapping("/selectRunCountByTime")
    @ApiOperation(value = "平均运动频次", notes = "平均运动频次", response = BaseResult.class)
    public BaseResult selectRunCountByTime(Integer year, Integer month, String[] name, Integer reqType) throws Exception {
        return analysisService.selectRunCountByTime(year, month, name, reqType);
    }


    //健身数据统计
    @PostMapping("/selectRunCount")
    public JSONObject selectRunCount(String date) throws Exception {
        return analysisService.selectRunCount(date);
    }

    @GetMapping("/selectRunNextDays")
    public BaseResult selectRunNextDays(Integer day,String date) throws Exception {
        return analysisService.selectRunNextDays(day,date);
    }



    /**
     * 按年月 日 查询运动人次
     * @param type 1 日 2 月 3 年
     * @return
     */
    @PostMapping("/selectRunCountYMD")
    public BaseResult selectRunCountYMD(Integer type,String time) throws Exception {
        return analysisService.selectRunCountYMD(type,time);
    }


    @PostMapping("/selectPeopleAnalysis")
    public BaseResult selectPeopleAnalysis() throws ParseException {
        return analysisService.selectPeopleAnalysis();
    }

    @PostMapping("/selectLocationAnalysis")
    public BaseResult selectLocationAnalysis() {
        return analysisService.selectLocationAnalysis();
    }

    /**
     *
     * @param type 0 上月 1当日 2 当月 3 当年
     * @return
     * @throws Exception
     */
    @PostMapping("/selectRunTypeAnalysis")
    public BaseResult selectRunTypeAnalysis(int type) throws Exception {
        return analysisService.selectRunTypeAnalysis(type);
    }

    //实时运动分析
    @PostMapping("/selectRunTypeAnalysisNow")
    public BaseResult selectRunTypeAnalysisNow(){
        return analysisService.selectRunTypeAnalysisNow();
    }

    //本市运动人群居住分析
    @PostMapping("/selectCityAnalysis")
    public BaseResult selectCityAnalysis(){
        return analysisService.selectCityAnalysis();
    }


    @RequestMapping("/selectCityLocal")
    public BaseResult selectCityLocal(Integer year, Integer month, String[] name){
        return analysisService.selectCityLocal(year,month,name);
    }

    @RequestMapping("/selectSuburbsGraph")
    public BaseResult selectSuburbsGraph(Integer year, Integer month, String[] name){
        return analysisService.selectSuburbsGraph(year,month,name);
    }

}
